package com.shangxia.monomer.study.designPatterns.structuralType.decorator;

import lombok.extern.slf4j.Slf4j;

/**
 * @ProjectName: monomer
 * @ClassName: DecoratorDemoSed
 * @Time: 2021/8/1
 * @Author: zhouy
 * @Description:
 * @Experience:
 */

@Slf4j
public class DecoratorDemoSed {
    public static void main(String[] args) {
        Person person = new Person();
        ClothingStyleDecorator whiteJacket = new WhiteJacket();
        ClothingStyleDecorator blackPants = new BlackPants();
        ClothingStyleDecorator shoe = new Shoe();
        whiteJacket.decorator(person);
        blackPants.decorator(whiteJacket);
        shoe.decorator(blackPants);
        shoe.show();
    }
}

class Person {
    public void show() {
        System.out.println("这是我的穿衣风格");
    }
}

abstract class ClothingStyleDecorator extends Person {
    private Person person;

    @Override
    public void show() {
        if (null != person) {
            person.show();
        }
    }

    public void decorator(Person person) {
        this.person = person;
    }
}

class WhiteJacket extends ClothingStyleDecorator {
    private Person person;

    @Override
    public void show() {
        System.out.println("白上衣");
        super.show();
    }
}

class BlackPants extends ClothingStyleDecorator {
    private Person person;

    @Override
    public void show() {
        System.out.println("黑裤子");
        super.show();
    }
}

class Shoe extends ClothingStyleDecorator {
    private Person person;

    @Override
    public void show() {
        System.out.println("鞋子");
        super.show();
    }
}